#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>

// 假设这是一个长时间的计算函数
int sum_sqr(int n)
{
    sleep(1);
    return n *n;
}


int main(int argc, char const *argv[])
{
    int items[5] = {1, 2, 3, 4, 5};
    int sqrs[5];
    struct timeval start, end;
    gettimeofday(&start, NULL);
    for (int i = 0; i < 5; i++)
    {
        sqrs[i] = sum_sqr(items[i]);
    }
    gettimeofday(&end, NULL);
    printf("time = %ld\n", end.tv_sec - start.tv_sec);

    // 累加
    int sum = 0;
    for (int i = 0; i < 5; i++)
    {
        sum += sqrs[i];
    }
    printf("sum = %d\n", sum);
    
    return 0;
}
